/**
 * 条形图组件
 * 水平条形图，用于展示分类数据
 */

import React from 'react';
import { Bar } from 'react-chartjs-2';
import { ChartData, ChartOptions } from '../types';

interface BarChartProps {
  data: ChartData;
  options?: ChartOptions;
  height?: number;
}

const BarChart: React.FC<BarChartProps> = ({
  data,
  options,
  height = 400,
}) => {
  const chartOptions: any = {
    ...options,
    indexAxis: 'y', // 水平方向
    scales: {
      x: {
        stacked: false,
        beginAtZero: true,
      },
      y: {
        stacked: false,
        beginAtZero: false,
      },
    },
  };

  return <Bar data={data as any} options={chartOptions} height={height} />;
};

export default BarChart;

